package com.kaka.bus.engine.borrow.zhima;

import com.kaka.bus.bean.HttpWrapper;
import com.kaka.bus.di.DataManager;
import com.kaka.bus.engine.RouterUtil;
import com.kaka.bus.manager.Result;
import com.kaka.bus.manager.T;
import com.kaka.bus.mvp.RxPresenter;
import com.kaka.bus.util.U;

import javax.inject.Inject;

/**
 * Created by OnionMac on 2018/1/16.
 */

public class ZhiMaPresenter extends RxPresenter<ZhiMaContract.View> implements ZhiMaContract.Presenter {

    @Inject
    public ZhiMaPresenter(DataManager dataManager) {
        super(dataManager);
    }

    @Override
    public void loadData(String userId) {


        addSubscribe(mDataManager
                .getApi()
                .zhima(userId, U.Sign(userId))
                .compose(T.D())
                .subscribeWith(new Result<HttpWrapper<String>>() {
                    @Override
                    protected void onSuccess(HttpWrapper<String> wrapper) {
                        mView.loadDataSuccess(wrapper);
                    }
                }));
    }

    @Override
    public void router(ZhiMaActivity zhiMaActivity) {
        mView.showDialog("查询节点中...");
        RouterUtil.router(zhiMaActivity, mDataManager.getApi(),mCompositeDisposable, () -> {
            mView.dissDialog();
        });
    }
}
